/**
 * 
 */
package gates;

import gates.internals.NBaseTransistor;
import gates.internals.Transistor;

/**
 * @author denis
 * 
 */
public class Not extends Gate {
	static {
		filename = "simple_not.properties";
	}
	
	public Not(int defect) {
		this(false, defect);
	}

	public Not(boolean in_1, int defect) {
		this(new GateInput(in_1), defect);
	}

	public Not(GateInput in_1, int defect) {
		input_1 = in_1;
		output = new GateOutput();
		bat = new Battery();
		gnd = new Ground();
		this.defect = defect;
		generateCircuit();
		super.setOldValues();
		sendSignals();
		saveValuesToFile();
	}
	
	private void sendSignals() {
		bat.sendSignal();
		gnd.sendSignal();
		input_1.sendSignal();
	}

	protected void generateCircuit() {
		NBaseTransistor nbTransistor = new NBaseTransistor("1", defect);
		defect--;
		bat.addObserver(nbTransistor.getCollector());
		input_1.addObserver(nbTransistor.getBase());

		Transistor transistor = new Transistor("2", defect);
		defect--;
		nbTransistor.getEmitter().addObserver(transistor.getCollector());
		input_1.addObserver(transistor.getBase());
		gnd.addObserver(transistor.getEmitter());

		nbTransistor.getEmitter().addObserver(output);
		transistor.getCollector().addObserver(output);
		components.add(nbTransistor);
		components.add(transistor);
	}

	public boolean getOutput() {
		return output.getValue();
	}

	public static void main(String... args) {
		Not not = new Not(new GateInput(false), 0);
		System.out.println(not.getOutput());
		And and = new And(new GateInput(not.getOutput()), new GateInput(false),
				0);
		System.out.println(and.getOutput());
	}
}
